package com.example.userdemo.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;

public enum LanguageEnum {
    /**
     * 其他
     */
    OTHER("other", "其他"),
    /**
     * 中文
     */
    ZH("zh", "中文"),
    /**
     * 英文
     */
    EN("en", "英文");

    @EnumValue
    private final String code;
    private final String desc;

    LanguageEnum(String code, String des) {
        this.code = code;
        this.desc = des;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static String getDescriptionOf(String code) {
        for (LanguageEnum language : LanguageEnum.values()) {
            if (language.getCode().equals(code)) {
                return language.getDesc();
            }
        }
        return null;
    }

    public static String getCodeByDesc(String desc) {
        for (LanguageEnum language : LanguageEnum.values()) {
            if (language.getDesc().equals(desc)) {
                return language.getCode();
            }
        }
        return null;
    }
}
